package com.chester.eurekaprovider.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author chester7cheng
 */
@RestController
@RequestMapping("/hello")
@Slf4j
public class HelloController {

    @Value("${server.port}")
    private int port;

    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/")
    public String hello(@RequestParam String name) {
        log.trace("services: " + discoveryClient.getServices());
        return "[" + port + "] " + "Hello, " + name + " " + LocalDateTime.now();
    }
}
